//
//  YMNodataView.m
//  LantaiyuanBus
//
//  Created by lantaiyuan on 16/9/24.
//  Copyright © 2016年 lantaiyuan. All rights reserved.

//  无数据页面

#import "YMNodataView.h"

@interface YMNodataView ()
@property (nonatomic, strong) UIImageView * imageView;
@property (nonatomic, strong) YYLabel * label;
@end

@implementation YMNodataView

- (instancetype)initBigImageWithFrame:(CGRect)frame image:(UIImage *)image title:(NSString *)title{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = CONTENT_BG_COLOR;
        
        // 图片
        [self addSubview:self.imageView];
        self.imageView.image = image;
        
        // 标题
        [self addSubview:self.label];
        
        NSMutableAttributedString * text = [[NSMutableAttributedString alloc] initWithString:title];
        text.font = [UIFont systemFontOfSize:15];
        text.color = GRAY_COLOR;
        text.lineSpacing = 10;
        
        WEAKSELF
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.mas_top).offset(165);
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.width.equalTo(@170);
            make.height.equalTo(@160);
        }];
        
        [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.imageView.mas_bottom).offset(14);
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.width.equalTo(@(SCREEN_WIDTH - 100));
            make.height.equalTo(@100);
        }];
        
        self.label.attributedText = text;
        self.label.numberOfLines = 0;
        self.label.textAlignment = NSTextAlignmentCenter;
        //self.label.backgroundColor = RED_COLOR;
        self.label.textVerticalAlignment = YYTextVerticalAlignmentTop;
    }
    return self;
}
/**
 无数据页面
 
 @param frame frame
 @param image 图片
 @param imageWidth 图片宽度
 @param title 文字
 @return 无数据对象
 */
-(instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image imageWidth:(CGFloat)imageWidth title:(NSString *)title{

    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = CONTENT_BG_COLOR;
        
        // 图片
        [self addSubview:self.imageView];
        self.imageView.image = image;
        
        // 标题
        [self addSubview:self.label];
        
        NSMutableAttributedString * text = [[NSMutableAttributedString alloc] initWithString:title];
        text.font = [UIFont systemFontOfSize:15];
        text.color = GRAY_COLOR;
        text.lineSpacing = 10;
        
        WEAKSELF
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.mas_top).offset(165);
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.width.equalTo(@(imageWidth));
            make.height.equalTo(@(imageWidth));
        }];
        
        [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.imageView.mas_bottom).offset(14);
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.width.equalTo(@(imageWidth + 20));
            make.height.equalTo(@100);
        }];
        
        self.label.attributedText = text;
        self.label.numberOfLines = 0;
        self.label.textAlignment = NSTextAlignmentCenter;
        //self.label.backgroundColor = RED_COLOR;
        self.label.textVerticalAlignment = YYTextVerticalAlignmentTop;
    }
    return self;
}

- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
    }
    return _imageView;
}

- (YYLabel *)label{
    if (!_label) {
        _label = [YYLabel new];
    }
    return _label;
}

@end
